/**
 * @param {number[]} nums
 * @return {number}
 */
var singleNumber = function (nums) {
  let map = {};
  for (let i = 0; i < nums.length; i++) {
    if (map[nums[i]]) {
      map[nums[i]]++;
    } else {
      map[nums[i]] = 1;
    }
  }
  for (let key in map) {
    if (map[key] === 1 && map.hasOwnProperty(key)) return +key;
  }
};

let arr = [2, 2, 1];
console.log(singleNumber(arr));
